//
//  Hello World client
//  Connects REQ socket to tcp://localhost:5559
//  Sends "Hello" to server, expects "World" back
//

package main

import (
	"fmt"
	"os"
	"zmq"
)

func zmq_main() os.Error {
	context, err := zmq.Init(1)
	if err != nil {
		return err
	}
	defer context.Close()

	requester, err := context.Socket(zmq.REQ)
	if err != nil {
		return err
	}
	defer requester.Close()

	err = requester.Connect("tcp://localhost:5559")
	if err != nil {
		return err
	}
	for i := 0; i < 10; i++ {
		err := requester.Send([]byte("Hello"), 0)
		if err != nil {
			return err
		}
		data, err := requester.Recv(0)
		if err != nil {
			return err
		}
		fmt.Printf("Received reply %d [%s]\n", i, data)
	}
	return nil
}

func main() {
	fmt.Println("Hello World client")
	err := zmq_main()
	if err != nil {
		fmt.Println(err)
	}
}
